﻿using System;
using System.Collections.Generic;
using System.Linq;
using DataScripter.Containers;
using DataScripter.Scripting.Processes;
using DataScripter.Scripting.Processes.Output;

namespace DataScripter.Scripting.ProcessDefinitions
{
    public class ProcessDefinition : IProcessDefinition
    {
        public string Name { get; set; }
        public IContainer Container { get; set; }
        private readonly IDictionary<string, IProcess> _processes = new Dictionary<string, IProcess>();

        public ProcessDefinition(string name, IContainer container)
        {
            Name = name;
            Container = container;
        }

        public void AddProcess(string name, IProcess process)
        {
            _processes.Add(name, process);
        }

        public IProcessOutput Run()
        {
            foreach (IProcess process in _processes.Values)
            {
                Output = process.Run();
            }
            return Output;
        }

        public IProcess GetProcessByName(string processName)
        {
            return _processes[processName];
        }

        public IProcessOutput Output { get; private set; }
    }
}
